package com.whut.common;

import com.whut.entity.Courier;
import com.whut.entity.User;

import javax.servlet.http.HttpSession;

public class UserUtil {
    /**
     * 获取登录验证码
     * @param session
     * @param userPhone
     * @return
     */
    public static String getLoginSms(HttpSession session, String userPhone){
        return (String) session.getAttribute(userPhone);
    }

    /**
     * 设置登录验证码
     * @param session
     * @param userPhone
     * @param code
     */
    public static void setLoginSms(HttpSession session, String userPhone, String code){
        session.setAttribute(userPhone, code);
    }

    /**
     * 方法重载，当前登录的可能是用户也可能是快递员
     * @param session
     * @param user
     */
    public static void setWxUser(HttpSession session, User user){
        session.setAttribute("wxUser", user);
        session.setAttribute("user", user.getId());
    }
    public static void setWxUser(HttpSession session, Courier courier){
        session.setAttribute("wxUser", courier);
        session.setAttribute("courier", courier.getId());
    }

    /**
     * 获取当前登录的用户or快递员
     * @param session
     * @return
     */
    public static Object getWxUser(HttpSession session){
        return session.getAttribute("wxUser");
    }

}
